/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.trandio.manager;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.trandio.dao.UtilidadesInterface;
import org.trandio.model.MedicoVO;
import org.trandio.model.PacienteVO;
import org.trandio.util.PlanoPacientes;

/**
 *
 * @author Edward Orozco
 */
public class ListarPlanos extends HttpServlet {


    MedicoVO medicoVO;
    UtilidadesInterface utilidadesInterface;
    private List<PacienteVO> listPaciente;



    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        String file = request.getParameter("dato");
        PlanoPacientes planoPacientes = new PlanoPacientes();

        try {

            File archivoErr = new File("/tmp/err_"+file+".txt");
                archivoErr.delete();



            int numeroErrores = planoPacientes.leePlanoPacientes("/tmp/"+file, ";", file);
            if(numeroErrores>0){
               out.println(numeroErrores);
            }else{
                planoPacientes.escribePlanoPacientes("/tmp/"+file, ";");
            }


        } catch (Exception ex) {
            Logger.getLogger(ListarPlanos.class.getName()).log(Level.SEVERE, null, ex);
        }

            /*
            out.println("<table width='99%' style='border:1px solid gray' class='extdt-caption'>");
            File dir = new File("/tmp");
            String[] chld = dir.list();
            if(chld == null){
              System.out.println("Specified directory does not exist or is not a directory.");
              System.exit(0);
            }else{
              for(int i = 0; i < chld.length; i++){
                String fileName = chld[i];
                //System.out.println(fileName);
                out.println("<tr><td>"+fileName+"</td></tr>");
              }
            }
            out.println("</table>");
            */

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}